﻿@model IEnumerable<MerchantTribe.Commerce.Orders.OrderSnapshot>

@{
    ViewBag.Title = "Order History";
    Layout = "~/Areas/Account/Views/Shared/_AccountLayout.cshtml";
}

@functions
{
    string OrderLink(MerchantTribe.Commerce.Orders.OrderSnapshot o)
    {
        if (o == null) return string.Empty;
        string toFormat = "~/account/orderhistory/details/{0}";
        if (!string.IsNullOrEmpty(o.AcumaticaId)) { toFormat += "?acumaticamod=1"; }
        return Url.Content(string.Format(toFormat, o.bvin));    
    }
}

@Html.Raw((string)TempData["messages"])
<h1>@ViewBag.Title</h1>
<table class="formtable centerall" width="100%">
<thead>
    <tr>
        <th>Order Number</th>
        <th>Amount</th>
        <th>Time of Order</th>
        <th>&nbsp;</th>
    </tr>
</thead>
@foreach (var o in Model)
{
    <tr>
        <td>@o.OrderNumber</td>
        <td>@o.TotalGrand.ToString("C")</td>
        <td>@o.TimeOfOrderUtc.ToLocalTime()</td>
        <td>
            <a href="@OrderLink(o)">
                <img src="@ViewBag.ViewButtonImageUrl" alt="View Details" />
            </a>
        </td>                                                
    </tr>
}
</table>
